/**
 * Created by yuzhou on 2020/3/10.
 */

//vue获取数据
$(document).ready(function () {
    //获取
    //轮播图数据
    var data = new Vue({
        el:'#whole_box',
        data:{
            imglist:[],
            getImgUrl:"/market/getAdvantage",
            moredata:[],
            a1:"",
            a2:"",
            a3:"",
            a4:"",
            a5:"",
            a6:"",
            a7:"",
            a8:"",
            a9:"",
            s1:"",
            s2:"",
            s3:"",
            s4:"",
            s5:"",
            s6:"",
            s7:"",
            s8:"",
            s9:"",
            s10:"",
            s11:"",
            s12:"",
            s13:"",
            s14:"",
            store_shaxi_list:[],
            store_haotai_list:[],
            store_shenyang_list:[],

            vr_txt:"市场VR",
            planeride_txt:"平面导购",
            traffice_txt:"交通指引",
            hot_recommend_txt:"热门商家",
            main_pro_txt:"主营",

            tab1:"信基沙溪(广州)",
            tab2:"信基豪泰(广州)",
            tab3:"信基沙溪(沈阳)",

            title:"信基沙溪",

            bottom1:"",
            bottom2:"",
            bottom3:"",

            is_en:false,

            brand_list_href : "/page/redirectBrandList?market_type=1",
            lanuage_type:"",

            page_num:1,
            current_tab:1,

            market_introduce_href : "/page/redirectAboutus?id=2",

            tab1_vr:"",
            tab2_vr:"",
            tab3_vr:"",

            search_txt:"",

            share_desc:"信基沙溪酒店用品博览城（广州）",
            share_url:"http://www.xinjisx.com/page/redirectMarketopens?id=1",

            current_tab_id:0,
        },
        created: function(){
            this.getImg();              //定义方法编译完成后执行
        },
        mounted:function(){
            var self = this;

            var market_id = self.getQueryValue("id");
            if(market_id == 1){
                $("#item_tab").attr("class","active");
                $("#home").attr("class","tab-pane active");
                self.share_url = "http://www.xinjisx.com/page/redirectMarketopens?id=1";
                self.getShaXiGZData();
            }else if(market_id == 2){
                $("#item_tab1").attr("class","active");
                $("#profile").attr("class","tab-pane active");
                self.share_url = "http://www.xinjisx.com/page/redirectMarketopens?id=2";
                self.getShaXiHTData();
            }else if(market_id == 3){
                $("#item_tab2").attr("class","active");
                $("#messages").attr("class","tab-pane active");
                self.share_url = "http://www.xinjisx.com/page/redirectMarketopens?id=3";
                self.getShaXiSYData();
            }else{
                $("#item_tab").attr("class","active");
                $("#home").attr("class","tab-pane active");
                self.share_url = "http://www.xinjisx.com/page/redirectMarketopens?id=1";
                self.getShaXiGZData();
            }



            self.lanuage_type = localStorage.getItem("language");
            if(self.lanuage_type == "cn"){ 
                self.changeToCn();
                //self.getShaXiGZData();
                localStorage.setItem("language", "cn");
            }else{
                self.changeToEn();
                //self.getShaXiGZData();
                localStorage.setItem("language", "en");
            }

            self.getVR();


            $("#btnCE").click(function () {
                var img = document.getElementById("btnCE");
                if(localStorage.getItem("language") =="cn"){
                    img.src = "/xj/image/English.png"
                    localStorage.setItem("language", "en");
                    img.alt="en"
                    self.changeToEn();
                    self.page_num = 1;
                    self.changeTab(self.current_tab_id);
                    self.is_en = true;
                }else{
                    img.src = "/xj/image/chinese.png"
                    localStorage.setItem("language", "cn");
                    img.alt="cn";
                    self.changeToCn();
                    self.page_num = 1;
                    self.changeTab(self.current_tab_id);
                    self.is_en = false;
                }
            });

            $.ajax({
                type:"GET",
                url:"/market/getWpConig",
                data: {
                    clientUrl:window.location.href.split("#")[0]
                },
                dataType:"json",
                success:function(res){
                    wx.config({
                        debug: false,
                        appId: res.appId, // 和获取Ticke的必须一样------必填，公众号的唯一标识
                        timestamp: res.timestamp, // 必填，生成签名的时间戳
                        nonceStr: res.nonceStr, // 必填，生成签名的随机串
                        signature: res.signature,// 必填，签名，见附录1
                        //需要分享的列表项:发送给朋友，分享到朋友圈，分享到QQ，分享到QQ空间
                        jsApiList: [
                            'onMenuShareAppMessage', 'onMenuShareTimeline',
                            'onMenuShareQQ', 'onMenuShareQZone'
                        ]
                    });


                }
            });


            $(window).scroll(function () {
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();

                if (Math.round(scrollTop + windowHeight) == scrollHeight) {
                    self.page_num += 6;
                    if(self.current_tab == 1){
                        self.getShaXiGZData();
                    }else if(self.current_tab == 2){
                        self.getShaXiHTData();
                    }else if(self.current_tab == 3){
                        self.getShaXiSYData();
                    }
                }
            });

            toastr.options = {
                // toastr配置
                "closeButton": true, //是否显示关闭按钮
                "debug": false, //是否使用debug模式
                "progressBar": true, //是否显示进度条，当为false时候不显示；当为true时候，显示进度条，当进度条缩短到0时候，消息通知弹窗消失
                "positionClass": "toast-bottom-center",//显示的动画位置
                "showDuration": "400", //显示的动画时间
                "hideDuration": "1000", //消失的动画时间
                "timeOut": "7000", //展现时间
                "extendedTimeOut": "1000", //加长展示时间
                "showEasing": "swing", //显示时的动画缓冲方式
                "hideEasing": "linear", //消失时的动画缓冲方式
                "showMethod": "fadeIn", //显示时的动画方式
                "hideMethod": "fadeOut" //消失时的动画方式
            }
        },
        methods: {
            getQueryValue:function (a) {
                var query = decodeURI(window.location.search.substring(1));
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == a) { return pair[1]; }
                }
                return null;
            },

            getVR:function () {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getVRUrl",
                    data: {
                        id:2
                    },
                    dataType:"text",
                    success:function(res){
                        self.tab1_vr = res;
                    }
                });

                $.ajax({
                    type:"GET",
                    url:"/market/getVRUrl",
                    data: {
                        id:3
                    },
                    dataType:"text",
                    success:function(res){
                        self.tab2_vr = res;
                    }
                });

                $.ajax({
                    type:"GET",
                    url:"/market/getVRUrl",
                    data: {
                        id:4
                    },
                    dataType:"text",
                    success:function(res){
                        self.tab3_vr = res;
                    }
                });
            },

            getImg: function(){
                var that = this;
                that.$http({           //调用接口
                    method:'post',
                    url:this.getImgUrl  //this指data
                }).then(function(response){  //接口返回数据

                    that.moredata = response.data;
                    console.log(JSON.stringify(that.moredata)+"xxx");
                    for(var i = 0;i<response.data.length;i++){
                        that.imglist.push("https://www.xinjisx.com"+"/wx/lubo/"+(response.data[i].pic_url)) ;
                        // console.log(that.imglist[i]);
                    }
                },function(error){
                    console.log("请求出错");
                })
            },

            getShaXiGZData:function () {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getMarketByType",
                    data: {
                        type_id:1,
                        language:localStorage.getItem("language"),
                        page:self.page_num
                    },
                    dataType:"json",
                    success:function(res){

                        if(self.page_num > 1){
                            self.store_shaxi_list = self.store_shaxi_list.concat(res);
                        }else{
                            self.store_shaxi_list = res;
                        }
                    }
                });
            },

            getShaXiHTData:function () {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getMarketByType",
                    data: {
                        type_id:2,
                        language:localStorage.getItem("language"),
                        page:self.page_num
                    },
                    dataType:"json",
                    success:function(res){
                        if(self.page_num > 1){
                            self.store_haotai_list = self.store_haotai_list.concat(res);
                        }else{
                            self.store_haotai_list = res;
                        }

                    }
                });
            },

            getShaXiSYData:function () {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getMarketByType",
                    data: {
                        type_id:3,
                        language:localStorage.getItem("language"),
                        page:self.page_num
                    },
                    dataType:"json",
                    success:function(res){
                        if(self.page_num > 1){
                            self.store_shenyang_list = self.store_shenyang_list.concat(res);
                        }else{
                            self.store_shenyang_list = res;
                        }

                    }
                });
            },

            changeToCn:function () {
                var self = this;
                self.a1 = "/xj/image/market_area/a.png";
                self.a2 = "/xj/image/market_area/b.png";
                self.a3 = "/xj/image/market_area/c.png";
                self.a4 = "/xj/image/market_area/d.png";
                self.a5 = "/xj/image/market_area/e.png";
                self.a6 = "/xj/image/market_area/f.png";
                self.a7 = "/xj/image/market_area/g.png";
                self.a8 = "/xj/image/market_area/h.png";
                self.a9 = "/xj/image/market_area/i.png";
                self.s1 ="/xj/image/market_area/1.png";
                self.s2 = "/xj/image/market_area/2.png";
                self.s3 = "/xj/image/market_area/3.png";
                self.s4 = "/xj/image/market_area/4.png";
                self.s5 = "/xj/image/market_area/5.png";
                self.s6 = "/xj/image/market_area/6.png";
                self.s7 = "/xj/image/market_area/7.png";
                self.s8 = "/xj/image/market_area/8.png";
                self.s9 = "/xj/image/market_area/9.png";
                self.s10 = "/xj/image/market_area/10.png";
                self.s11 = "/xj/image/market_area/11.png";
                self.s12 = "/xj/image/market_area/12.png";
                self.s13 = "/xj/image/market_area/13.png";
                self.s14 = "/xj/image/market_area/super.png";
                self.vr_txt = "市场VR";
                self.planeride_txt = "平面导购";
                self.traffice_txt = "交通指引";
                self.hot_recommend_txt = "热门商家";
                self.main_pro_txt = "主营";
                self.tab1 = "信基沙溪(广州)";
                self.tab2 = "信基豪泰(广州)";
                self.tab3 = "信基沙溪(沈阳)";
                self.title = "信基沙溪";
                self.bottom1 = "市场介绍";
                self.bottom2 = "品牌商家";
                self.bottom3 = "联系我们";
                self.is_en = false;
                self.search_txt="搜索更多..";
            },

            changeToEn:function () {
                var self = this;
                self.a1 = "/xj/image/market_area/a_en.png";
                self.a2 = "/xj/image/market_area/b_en.png";
                self.a3 = "/xj/image/market_area/c_en.png";
                self.a4 = "/xj/image/market_area/d_en.png";
                self.a5 = "/xj/image/market_area/e_en.png";
                self.a6 = "/xj/image/market_area/f_en.png";
                self.a7 = "/xj/image/market_area/g_en.png";
                self.a8 = "/xj/image/market_area/h_en.png";
                self.a9 = "/xj/image/market_area/i_en.png";
                self.s1 ="/xj/image/market_area/1_en.png";
                self.s2 = "/xj/image/market_area/2_en.png";
                self.s3 = "/xj/image/market_area/3_en.png";
                self.s4 = "/xj/image/market_area/4_en.png";
                self.s5 = "/xj/image/market_area/5_en.png";
                self.s6 = "/xj/image/market_area/6_en.png";
                self.s7 = "/xj/image/market_area/7_en.png";
                self.s8 = "/xj/image/market_area/8_en.png";
                self.s9 = "/xj/image/market_area/9_en.png";
                self.s10 = "/xj/image/market_area/10_en.png";
                self.s11 = "/xj/image/market_area/11_en.png";
                self.s12 = "/xj/image/market_area/12_en.png";
                self.s13 = "/xj/image/market_area/13_en.png";
                self.s14 = "/xj/image/market_area/super_en.png";
                self.vr_txt = "VR Guide";
                self.planeride_txt = "Layout";
                self.traffice_txt = "Traffic";
                self.hot_recommend_txt = "Hot Recommended";
                self.main_pro_txt = "Main Products";
                self.tab1 = "XinJi ShaXi (Guangzhou)";
                self.tab2 = "XinJi Hotelex (Guangzhou)";
                self.tab3 = "XinJi Shaxi (Shenyang)";
                self.bottom1 = "Introduction";
                self.bottom2 = "Brand Shops";
                self.bottom3 = "Contact Us";
                self.is_en = true;
                self.search_txt="Search More..";

            },
            areaGo:function (a,b,c) {
                window.location.href="/page/redirectStore?market="+a+"&name="+b+"&area="+c;
            },

            changeTab:function (a) {
                var self = this;
                self.current_tab_id = a;
                if(a == 1){
                    self.share_desc = "信基沙溪酒店用品博览城（广州）";
                    self.page_num = 1;
                    self.current_tab = 1;
                    self.market_introduce_href = "/page/redirectAboutus?id=2";
                    self.getShaXiGZData();
                }else if(a == 2){
                    self.share_desc = "信基豪泰酒店用品城";
                    self.page_num = 1;
                    self.current_tab = 2;
                    self.market_introduce_href = "/page/redirectAboutus?id=3";
                    self.getShaXiHTData();
                }else if(a == 3){
                    self.share_desc = "信基沙溪酒店用品博览城（沈阳）";
                    self.page_num = 1;
                    self.current_tab = 3;
                    self.market_introduce_href = "/page/redirectAboutus?id=4";
                    self.getShaXiSYData();
                }
                self.brand_list_href  =  "/page/redirectBrandList?market_type="+a;
                var share_config = {
                    "imgUrl": "http://www.xinjisx.com/img/logo.jpg",
                    "desc": self.share_desc,
                    "title": self.share_desc,
                    "link": self.share_url,
                    "success": function () {
                        //分享成功后的回调函数
                        // alert('分享成功')
                    },
                    "cancel": function () {
                        //用户取消分享执行的回调函数
                        // alert('分享成功')
                    }
                };

                wx.ready(function () {
                    wx.onMenuShareAppMessage(share_config);//分享给好友
                    wx.onMenuShareTimeline(share_config);//分享到朋友圈
                });
            },

            storDetail:function (a) {
                window.location.href = "/page/redirectStoreDeatil?id="+a;
            },

            goSearch:function () {
                window.location.href="/page/redirectSearch";
            },
            
            shenyangVR:function () {
                toastr.info("提示尚未开通，敬请期待");
            }

        }

    });


});

$(document).ready(function() {
    $(".g-scrolling-carousel .items").gScrollingCarousel();
    $("#store_item").click(function () {
        window.location.href = "/page/redirectStoreDeatil";
    })
});




